﻿Public Class jbgw
    Private _caption As String
    Private _quantity As Integer
    Private _UpDn As Integer '1:正转 -1：反转
    Private _PowerON As Boolean
    Private _Connected As Boolean
    Private _MDD As String
    Private _DefaultLK As Integer
    Private _colNo As Integer
    Public controlmode As Boolean
    ' Private _dr As DataRow
    Public Property Caption As String
        Get
            Return _caption
        End Get
        Set(value As String)
            _caption = value
            txtCaption.Text = value
        End Set
    End Property

    Public Property Quantity As Integer
        Get
            Return _quantity
        End Get
        Set(value As Integer)
            _quantity = value

            lk1.BackColor = Color.White
            lk2.BackColor = Color.White
            lk3.BackColor = Color.White
            lk4.BackColor = Color.White
            If UpDn = 1 Then
                Dim _count As Integer = 1
                For i As Integer = 4 To 1 Step -1
                    Dim obj As Panel = lk1.Parent.Controls.Find(String.Format("lk{0}", i), False)(0)
                    If obj.Visible = True Then
                        If _count <= _quantity Then
                            obj.BackColor = Color.Black
                            _count = _count + 1
                        End If
                    End If
                Next
            Else
                Dim _count As Integer = 1
                For i As Integer = 1 To 4 Step 1
                    Dim obj As Panel = lk1.Parent.Controls.Find(String.Format("lk{0}", i), False)(0)

                    If obj.Visible = True Then
                        If _count <= _quantity Then
                            obj.BackColor = Color.Black
                            _count = _count + 1
                        End If
                    End If
                Next
            End If

        End Set
    End Property

    Public Property UpDn As Integer
        Get
            Return _UpDn
        End Get
        Set(value As Integer)
            _UpDn = value
        End Set
    End Property

    Public Property PowerON As Boolean
        Get
            Return _PowerON
        End Get
        Set(value As Boolean)
            _PowerON = value
            If value Then
                pipe.MoveSpeed = _UpDn
            Else
                pipe.MoveSpeed = 0
            End If
        End Set
    End Property

    Public Property Connected As Boolean
        Get
            Return _Connected
        End Get
        Set(value As Boolean)
            _Connected = value
            If value Then
                txtCaption.BackColor = Color.Lime
                txtCaption.ForeColor = Color.Black
            Else
                txtCaption.BackColor = Color.Red
                txtCaption.ForeColor = Color.White
            End If
        End Set
    End Property

    Public Property MDD As String
        Get
            Return _MDD
        End Get
        Set(value As String)
            _MDD = value
        End Set
    End Property

    Public Property DefaultLK As Integer
        Get
            Return _DefaultLK
        End Get
        Set(value As Integer)
            _DefaultLK = value
            lk1.Visible = False
            lk2.Visible = False
            lk3.Visible = False
            lk4.Visible = False
            If value >= 1 Then lk1.Visible = True
            If value >= 2 Then lk2.Visible = True
            If value >= 3 Then lk3.Visible = True
            If value >= 4 Then lk4.Visible = True

        End Set
    End Property

    Public Property ColNo As Integer
        Get
            Return _colNo
        End Get
        Set(value As Integer)
            _colNo = value
            lblColNo.Text = value.ToString.PadLeft(2, "0")
        End Set
    End Property

    Public Sub setStatus(_dr As DataRow, _car1_Loc As String, _car2_Loc As String) ', _strMDD As String)
        'MDD = _strMDD
        If IsNothing(_dr) Then Exit Sub
        Try
            Me.Connected = IIf(DBNULLtoBlank(_dr("gwComm")) = "", False, _dr("gwComm"))
            If Me.Connected Then
                lanStop.Visible = IIf(DBNULLtoBlank(_dr("stop")) = "", False, _dr("stop"))
                Me.Quantity = DBNULLtoZero(_dr("gwLKNum"))

                Select Case DBNULLtoZero(_dr("gwLKSize"))
                    Case 1
                        lblSize.Text = "小"
                    Case 2
                        lblSize.Text = "中"
                    Case 3
                        lblSize.Text = "大"
                    Case Else
                        lblSize.Text = ""
                End Select

                If DBNULLtoZero(_dr("mesPlanNum")) = "0" Then
                    lblMesPlanNum.Visible = False
                    lblMesPlanNum.Text = ""
                Else
                    lblMesPlanNum.Visible = True
                    lblMesPlanNum.Text = DBNULLtoZero(_dr("mesPlanNum"))
                End If

                lbl_1_Num.Text = DBNULLtoZero(_dr("gw1Sum"))

                If UpDn = -1 Then
                    Me.PowerON = IIf(DBNULLtoBlank(_dr("upFlg")) = "", False, _dr("upFlg"))
                Else
                    Me.PowerON = IIf(DBNULLtoBlank(_dr("dnFlg")) = "", False, _dr("dnFlg"))
                End If
            End If
            Dim MDDs As String() = MDD.Split(",")

            If MDDs(0) = _car1_Loc Or MDDs(1) = _car2_Loc Or MDDs(0) = _car2_Loc Or MDDs(1) = _car1_Loc Then
                pnlMDD.BackColor = Color.Lime
            Else
                pnlMDD.BackColor = Color.Gainsboro
            End If

            controlmode = _dr("controlmode")
            If _dr("controlmode") = True Then
                lblAM.Text = "自动"
                lblAM.ForeColor = Color.Black
                lblAM.BackColor = Color.LawnGreen
            Else
                lblAM.Text = "手动"
                lblAM.ForeColor = Color.White
                lblAM.BackColor = Color.Red

            End If
        Catch ex As Exception
            Throw ex
        End Try

    End Sub
End Class
